<?php $this->load->view('common/admin_header');?>
<div class="block">
  <div class="block_head">
    <div class="bheadl"></div>
    <div class="bheadr"></div>
    <h2>訂單統計</h2>
   <!--  <ul>
      <li><a href="javascript:void(0);" onClick="promotion_url('<?=site_url('admins/promotion/order')?>');" ><i class="icon-gift"></i><?=$lang['orders_lable_3']?></a></li>
    </ul> -->
  </div>
  <!-- .block_head ends -->
  <div class="block_content">
    <div class="breadcrumb" style="padding:0 0 15px 0 ">
      <form action="<?php echo base_url('admins/orders/report');?>" id="fs_form">
        <input type="hidden" value="0" name="isExport" id="_isExport" />
        <input type="text" class="stext" value="<?php echo $startDate;?>" style="padding:3px 5px;" name="satrtDate" id="_satrtDate" onfocus="WdatePicker()"> - 
        <input class="stext small" value="<?php echo $endDate;?>" style="padding:3px 5px;" type="text" name="endDate" id="_satrtDate" onfocus="WdatePicker()">
        <button class="btn btn-small btn-primary" id="_submit" type="button">篩 選</button>
        <button href="#" class="btn btn-small btn-danger " id="_export" type="button">導 出</button>
      </form>
    </div>
    <?php $this->load->view('common/notify');?>
     <table class="sortable" cellspacing="0" cellpadding="0" width="100%" style="margin-bottom: 0px;">
       <thead>
         <tr>
           <th width="100">日期</th>
           <th width="100">總額</th>
           <th width="100">單數</th>
           <?php if($results):?>
           <?php foreach($results['prodcuts'] as $prodcut_id=>$prodcut_name):?>
           <th width="80"><?php echo $prodcut_name;?></th>
           <?php endforeach;?>
           <?php endif;?> 
           <th ></th>
         </tr>
       </thead>
     </table>
     <div>
        <table class="sortable" cellspacing="0" cellpadding="0" width="100%">
         <tbody>

         <?php $total_add = $count_all = 0;?>
         <?php if($orders):?>
         <?php foreach($orders as $order):?>
          <?php 
              $total_add += $order['total'];
              $count_all += $order['nums'];
          ?>
           <tr>
             <td  width="100"><?php echo $order['order_date'];?></td>
             <td width="100"><?php echo $order['total'];?></td>
             <td width="100" width="100" ><?php echo $order['nums'];?></td>
             <?php foreach($results['prodcuts'] as $_id=>$_name):?>
              <td width="80"><?php echo isset($results['base'][$order['order_date']][$_id]) ? $results['base'][$order['order_date']][$_id] : 'N';?></td>
             <?php endforeach;?>
             <td ></td>
           </tr>
         <?php endforeach;?>
          <?php endif;?> 
         </tbody>
         
       </table>
       <div>
       <b>營業總額：HK$ <?php echo sprintf("%.2f",$total_add);?>　　　　　</b>
       <b>營業總單：<?php echo $count_all;?></b>
       </div>
     </div>
  </div>
  <!-- .block_content ends -->
  <div class="bendl"></div>
  <div class="bendr"></div>
</div>
<!-- .block ends -->
<script type="text/javascript">
    $("#_submit").click(function(){
        $("#_isExport").val(0);
        $("#fs_form").submit();
    })
    $("#_export").click(function(){
        $("#_isExport").val(1);
        $("#fs_form").submit();
    })
</script>
<?php $this->load->view('common/admin_footer');?>
